{
 "cells": [
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "# Downloading Data using Google Earth Engine Python API\n",
    "\n",
    "Note: Before running this notebook make sure you installed the neccesary packges and set up the authentication for GEE as described in the document.\n",
    "\n",
    "Packages required:\n",
    "```\n",
    "pip install earthengine-api\n",
    "pip install folium\n",
    "pip install geehydro\n",
    "```"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 1,
   "metadata": {},
   "outputs": [],
   "source": [
    "# import packages\n",
    "import ee\n",
    "import folium\n",
    "import geehydro\n",
    "from IPython.display import Image"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "### Initialize the connection\n",
    "When you use the API, the first thing you need to do is to initialize the connection to the server:"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 2,
   "metadata": {},
   "outputs": [],
   "source": [
    "ee.Initialize()"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "###  Area of Interest\n",
    "With satellite imagery you can investigate any spot on Earth. Select a region in the world you are interested on. Make sure that the projection for th e coordinates is in epsg:4326"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 6,
   "metadata": {},
   "outputs": [],
   "source": [
    "geometry = ee.Geometry.Polygon([ [ [ 74.78773234410812, 21.0595214900118745 ], [ 74.351701190523794, 21.091442728540564 ], [ 74.38934656420032073, 21.084363329949862 ], [ 74.38561416973411, 21.0568038201353 ], [ 74.2951443234410812, 21.0460214900118745 ], [ 74.78773234410812, 21.0595214900118745 ]  ] ])"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "### The Sentinel 2 Collection\n",
    "In GEE each collection has its own id. The snippet id for the LSentinel-2 MSI: MultiSpectral Instrument, Level-2A product is “COPERNICUS/S2_SR”.\n",
    "\n",
    "You can have access to the Sentinel 2 collection with the following code:"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "metadata": {},
   "outputs": [],
   "source": [
    "sentinel2_aoi = ee.ImageCollection(\"COPERNICUS/S2_SR\")"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "### Filtering the collection\n",
    "There are many filters you can apply to the collection. Let’s discuss the most common ones.\n",
    "\n",
    "#### Filtering to the area of interest\n",
    "The “.filterBounds()” method allows to select the geometry defined above.\n",
    "\n",
    "#### Filtering by date range\n",
    "The “.filterDate()” method allows to filter by date range.\n",
    "\n",
    "#### Filtering by Max Percentage of Cloud\n",
    "The “ee.Filter.lt(‘CLOUDY_PIXEL_PERCENTAGE’, use_scenes_with_max_cloud_percentage_of)” method allows to filter by cloud percentage."
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "#### Masking out clouds\n",
    "Most satellite imagery comes with cloud mask that can be used to mask out clouds from imagery. The following function mask out clouds for Sentinel 2 images."
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 5,
   "metadata": {},
   "outputs": [],
   "source": [
    "def maskS2clouds(image):\n",
    "    qa = image.select('QA60')\n",
    "    # Bits 10 and 11 are clouds and cirrus, respectively.\n",
    "    cloudBitMask = 1 << 10\n",
    "    cirrusBitMask = 1 << 11\n",
    "    # Both flags should be set to zero, indicating clear conditions.\n",
    "    mask = qa.bitwiseAnd(cloudBitMask).eq(0).And(qa.bitwiseAnd(cirrusBitMask).eq(0))\n",
    "    return image.updateMask(mask)"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "#### Combining all filters and getting median image from all images in a date range\n",
    "\n",
    "Filters can be combined. The following example gives you the median image from all images in a date range with maximum cloud coverage of 3% and clouds masked out"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 44,
   "metadata": {},
   "outputs": [],
   "source": [
    "sentinel2_aoi = ee.ImageCollection(\"COPERNICUS/S2_SR\").filterBounds(geometry)\n",
    "sentinel2_median_image = sentinel2_aoi.filterDate('2019-05-15', '2019-05-30').filter(ee.Filter.lt('CLOUDY_PIXEL_PERCENTAGE',3)).map(maskS2clouds).median()\n"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "### Meta-data\n",
    "You can easily .getInfo() about the Landsat collection above or any particular information you might be interested in."
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 46,
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/plain": [
       "{'type': 'Image',\n",
       " 'bands': [{'id': 'B1',\n",
       "   'data_type': {'type': 'PixelType',\n",
       "    'precision': 'int',\n",
       "    'min': 0,\n",
       "    'max': 65535},\n",
       "   'dimensions': [1830, 1830],\n",
       "   'crs': 'EPSG:32643',\n",
       "   'crs_transform': [60, 0, 399960, 0, -60, 2400000]},\n",
       "  {'id': 'B2',\n",
       "   'data_type': {'type': 'PixelType',\n",
       "    'precision': 'int',\n",
       "    'min': 0,\n",
       "    'max': 65535},\n",
       "   'dimensions': [10980, 10980],\n",
       "   'crs': 'EPSG:32643',\n",
       "   'crs_transform': [10, 0, 399960, 0, -10, 2400000]},\n",
       "  {'id': 'B3',\n",
       "   'data_type': {'type': 'PixelType',\n",
       "    'precision': 'int',\n",
       "    'min': 0,\n",
       "    'max': 65535},\n",
       "   'dimensions': [10980, 10980],\n",
       "   'crs': 'EPSG:32643',\n",
       "   'crs_transform': [10, 0, 399960, 0, -10, 2400000]},\n",
       "  {'id': 'B4',\n",
       "   'data_type': {'type': 'PixelType',\n",
       "    'precision': 'int',\n",
       "    'min': 0,\n",
       "    'max': 65535},\n",
       "   'dimensions': [10980, 10980],\n",
       "   'crs': 'EPSG:32643',\n",
       "   'crs_transform': [10, 0, 399960, 0, -10, 2400000]},\n",
       "  {'id': 'B5',\n",
       "   'data_type': {'type': 'PixelType',\n",
       "    'precision': 'int',\n",
       "    'min': 0,\n",
       "    'max': 65535},\n",
       "   'dimensions': [5490, 5490],\n",
       "   'crs': 'EPSG:32643',\n",
       "   'crs_transform': [20, 0, 399960, 0, -20, 2400000]},\n",
       "  {'id': 'B6',\n",
       "   'data_type': {'type': 'PixelType',\n",
       "    'precision': 'int',\n",
       "    'min': 0,\n",
       "    'max': 65535},\n",
       "   'dimensions': [5490, 5490],\n",
       "   'crs': 'EPSG:32643',\n",
       "   'crs_transform': [20, 0, 399960, 0, -20, 2400000]},\n",
       "  {'id': 'B7',\n",
       "   'data_type': {'type': 'PixelType',\n",
       "    'precision': 'int',\n",
       "    'min': 0,\n",
       "    'max': 65535},\n",
       "   'dimensions': [5490, 5490],\n",
       "   'crs': 'EPSG:32643',\n",
       "   'crs_transform': [20, 0, 399960, 0, -20, 2400000]},\n",
       "  {'id': 'B8',\n",
       "   'data_type': {'type': 'PixelType',\n",
       "    'precision': 'int',\n",
       "    'min': 0,\n",
       "    'max': 65535},\n",
       "   'dimensions': [10980, 10980],\n",
       "   'crs': 'EPSG:32643',\n",
       "   'crs_transform': [10, 0, 399960, 0, -10, 2400000]},\n",
       "  {'id': 'B8A',\n",
       "   'data_type': {'type': 'PixelType',\n",
       "    'precision': 'int',\n",
       "    'min': 0,\n",
       "    'max': 65535},\n",
       "   'dimensions': [5490, 5490],\n",
       "   'crs': 'EPSG:32643',\n",
       "   'crs_transform': [20, 0, 399960, 0, -20, 2400000]},\n",
       "  {'id': 'B9',\n",
       "   'data_type': {'type': 'PixelType',\n",
       "    'precision': 'int',\n",
       "    'min': 0,\n",
       "    'max': 65535},\n",
       "   'dimensions': [1830, 1830],\n",
       "   'crs': 'EPSG:32643',\n",
       "   'crs_transform': [60, 0, 399960, 0, -60, 2400000]},\n",
       "  {'id': 'B11',\n",
       "   'data_type': {'type': 'PixelType',\n",
       "    'precision': 'int',\n",
       "    'min': 0,\n",
       "    'max': 65535},\n",
       "   'dimensions': [5490, 5490],\n",
       "   'crs': 'EPSG:32643',\n",
       "   'crs_transform': [20, 0, 399960, 0, -20, 2400000]},\n",
       "  {'id': 'B12',\n",
       "   'data_type': {'type': 'PixelType',\n",
       "    'precision': 'int',\n",
       "    'min': 0,\n",
       "    'max': 65535},\n",
       "   'dimensions': [5490, 5490],\n",
       "   'crs': 'EPSG:32643',\n",
       "   'crs_transform': [20, 0, 399960, 0, -20, 2400000]},\n",
       "  {'id': 'AOT',\n",
       "   'data_type': {'type': 'PixelType',\n",
       "    'precision': 'int',\n",
       "    'min': 0,\n",
       "    'max': 65535},\n",
       "   'dimensions': [10980, 10980],\n",
       "   'crs': 'EPSG:32643',\n",
       "   'crs_transform': [10, 0, 399960, 0, -10, 2400000]},\n",
       "  {'id': 'WVP',\n",
       "   'data_type': {'type': 'PixelType',\n",
       "    'precision': 'int',\n",
       "    'min': 0,\n",
       "    'max': 65535},\n",
       "   'dimensions': [10980, 10980],\n",
       "   'crs': 'EPSG:32643',\n",
       "   'crs_transform': [10, 0, 399960, 0, -10, 2400000]},\n",
       "  {'id': 'SCL',\n",
       "   'data_type': {'type': 'PixelType',\n",
       "    'precision': 'int',\n",
       "    'min': 0,\n",
       "    'max': 255},\n",
       "   'dimensions': [5490, 5490],\n",
       "   'crs': 'EPSG:32643',\n",
       "   'crs_transform': [20, 0, 399960, 0, -20, 2400000]},\n",
       "  {'id': 'TCI_R',\n",
       "   'data_type': {'type': 'PixelType',\n",
       "    'precision': 'int',\n",
       "    'min': 0,\n",
       "    'max': 255},\n",
       "   'dimensions': [10980, 10980],\n",
       "   'crs': 'EPSG:32643',\n",
       "   'crs_transform': [10, 0, 399960, 0, -10, 2400000]},\n",
       "  {'id': 'TCI_G',\n",
       "   'data_type': {'type': 'PixelType',\n",
       "    'precision': 'int',\n",
       "    'min': 0,\n",
       "    'max': 255},\n",
       "   'dimensions': [10980, 10980],\n",
       "   'crs': 'EPSG:32643',\n",
       "   'crs_transform': [10, 0, 399960, 0, -10, 2400000]},\n",
       "  {'id': 'TCI_B',\n",
       "   'data_type': {'type': 'PixelType',\n",
       "    'precision': 'int',\n",
       "    'min': 0,\n",
       "    'max': 255},\n",
       "   'dimensions': [10980, 10980],\n",
       "   'crs': 'EPSG:32643',\n",
       "   'crs_transform': [10, 0, 399960, 0, -10, 2400000]},\n",
       "  {'id': 'MSK_CLDPRB',\n",
       "   'data_type': {'type': 'PixelType',\n",
       "    'precision': 'int',\n",
       "    'min': 0,\n",
       "    'max': 255},\n",
       "   'dimensions': [5490, 5490],\n",
       "   'crs': 'EPSG:32643',\n",
       "   'crs_transform': [20, 0, 399960, 0, -20, 2400000]},\n",
       "  {'id': 'MSK_SNWPRB',\n",
       "   'data_type': {'type': 'PixelType',\n",
       "    'precision': 'int',\n",
       "    'min': 0,\n",
       "    'max': 255},\n",
       "   'dimensions': [5490, 5490],\n",
       "   'crs': 'EPSG:32643',\n",
       "   'crs_transform': [20, 0, 399960, 0, -20, 2400000]},\n",
       "  {'id': 'QA10',\n",
       "   'data_type': {'type': 'PixelType',\n",
       "    'precision': 'int',\n",
       "    'min': 0,\n",
       "    'max': 65535},\n",
       "   'dimensions': [10980, 10980],\n",
       "   'crs': 'EPSG:32643',\n",
       "   'crs_transform': [10, 0, 399960, 0, -10, 2400000]},\n",
       "  {'id': 'QA20',\n",
       "   'data_type': {'type': 'PixelType',\n",
       "    'precision': 'int',\n",
       "    'min': 0,\n",
       "    'max': 4294967295},\n",
       "   'dimensions': [5490, 5490],\n",
       "   'crs': 'EPSG:32643',\n",
       "   'crs_transform': [20, 0, 399960, 0, -20, 2400000]},\n",
       "  {'id': 'QA60',\n",
       "   'data_type': {'type': 'PixelType',\n",
       "    'precision': 'int',\n",
       "    'min': 0,\n",
       "    'max': 65535},\n",
       "   'dimensions': [1830, 1830],\n",
       "   'crs': 'EPSG:32643',\n",
       "   'crs_transform': [60, 0, 399960, 0, -60, 2400000]}],\n",
       " 'id': 'COPERNICUS/S2_SR/20181216T053229_20181216T053648_T43QDD',\n",
       " 'version': 1557019036764824,\n",
       " 'properties': {'DATATAKE_IDENTIFIER': 'GS2B_20181216T053229_009283_N02.11',\n",
       "  'AOT_RETRIEVAL_ACCURACY': 0,\n",
       "  'SPACECRAFT_NAME': 'Sentinel-2B',\n",
       "  'SATURATED_DEFECTIVE_PIXEL_PERCENTAGE': 0,\n",
       "  'MEAN_INCIDENCE_AZIMUTH_ANGLE_B8A': 101.827653676,\n",
       "  'CLOUD_SHADOW_PERCENTAGE': 0.002512,\n",
       "  'MEAN_SOLAR_AZIMUTH_ANGLE': 156.882544566,\n",
       "  'system:footprint': {'type': 'LinearRing',\n",
       "   'coordinates': [[75.09417836584879, 21.703479811089462],\n",
       "    [75.09416624781078, 21.703480566373408],\n",
       "    [74.03286590029424, 21.700686426771668],\n",
       "    [74.03282152315424, 21.700649616410885],\n",
       "    [74.03277257381208, 21.7006182803775],\n",
       "    [74.03276961533496, 21.700603489581212],\n",
       "    [74.03603484959169, 21.204726545453685],\n",
       "    [74.03920670448203, 20.708827583767803],\n",
       "    [74.03924605985753, 20.708786330930327],\n",
       "    [74.03927958812089, 20.70874081564098],\n",
       "    [74.03929536612513, 20.70873815527809],\n",
       "    [75.09353931628873, 20.711392827905236],\n",
       "    [75.09358368986327, 20.711429373301588],\n",
       "    [75.09363260770519, 20.711460465337474],\n",
       "    [75.09363563722495, 20.71147518855895],\n",
       "    [75.09426301388268, 21.70339046877172],\n",
       "    [75.09422371937994, 21.70343195606705],\n",
       "    [75.09419030567946, 21.70347770837096],\n",
       "    [75.09417836584879, 21.703479811089462]]},\n",
       "  'VEGETATION_PERCENTAGE': 9.397262,\n",
       "  'SOLAR_IRRADIANCE_B12': 87.75,\n",
       "  'SOLAR_IRRADIANCE_B10': 365.41,\n",
       "  'SENSOR_QUALITY': 'PASSED',\n",
       "  'SOLAR_IRRADIANCE_B11': 247.08,\n",
       "  'GENERATION_TIME': 1544953125000,\n",
       "  'SOLAR_IRRADIANCE_B8A': 953.93,\n",
       "  'FORMAT_CORRECTNESS': 'PASSED',\n",
       "  'CLOUD_COVERAGE_ASSESSMENT': 0.065106,\n",
       "  'THIN_CIRRUS_PERCENTAGE': 0.018796,\n",
       "  'system:time_end': 1544938983000,\n",
       "  'WATER_VAPOUR_RETRIEVAL_ACCURACY': 0,\n",
       "  'system:time_start': 1544938983000,\n",
       "  'DATASTRIP_ID': 'S2B_OPER_MSI_L2A_DS_SGS__20181216T093845_S20181216T053648_N02.11',\n",
       "  'PROCESSING_BASELINE': '02.11',\n",
       "  'SENSING_ORBIT_NUMBER': 105,\n",
       "  'NODATA_PIXEL_PERCENTAGE': 0,\n",
       "  'SENSING_ORBIT_DIRECTION': 'DESCENDING',\n",
       "  'GENERAL_QUALITY': 'PASSED',\n",
       "  'GRANULE_ID': 'L2A_T43QDD_A009283_20181216T053648',\n",
       "  'REFLECTANCE_CONVERSION_CORRECTION': 1.0318175782,\n",
       "  'MEDIUM_PROBA_CLOUDS_PERCENTAGE': 0.04504,\n",
       "  'MEAN_INCIDENCE_AZIMUTH_ANGLE_B8': 105.166420027,\n",
       "  'DATATAKE_TYPE': 'INS-NOBS',\n",
       "  'MEAN_INCIDENCE_AZIMUTH_ANGLE_B9': 101.406291067,\n",
       "  'MEAN_INCIDENCE_AZIMUTH_ANGLE_B6': 102.404478668,\n",
       "  'MEAN_INCIDENCE_AZIMUTH_ANGLE_B7': 102.09886834,\n",
       "  'MEAN_INCIDENCE_AZIMUTH_ANGLE_B4': 103.233631205,\n",
       "  'MEAN_INCIDENCE_ZENITH_ANGLE_B1': 4.75195230663,\n",
       "  'NOT_VEGETATED_PERCENTAGE': 56.191123,\n",
       "  'MEAN_INCIDENCE_AZIMUTH_ANGLE_B5': 102.790785936,\n",
       "  'RADIOMETRIC_QUALITY': 'PASSED',\n",
       "  'MEAN_INCIDENCE_AZIMUTH_ANGLE_B2': 106.188222034,\n",
       "  'MEAN_INCIDENCE_AZIMUTH_ANGLE_B3': 104.352249829,\n",
       "  'MEAN_INCIDENCE_ZENITH_ANGLE_B5': 4.50353472784,\n",
       "  'MEAN_INCIDENCE_AZIMUTH_ANGLE_B1': 101.609994246,\n",
       "  'MEAN_INCIDENCE_ZENITH_ANGLE_B4': 4.44983105562,\n",
       "  'MEAN_INCIDENCE_ZENITH_ANGLE_B3': 4.36236692449,\n",
       "  'MEAN_INCIDENCE_ZENITH_ANGLE_B2': 4.28654536397,\n",
       "  'MEAN_INCIDENCE_ZENITH_ANGLE_B9': 4.8247126219,\n",
       "  'MEAN_INCIDENCE_ZENITH_ANGLE_B8': 4.32165901475,\n",
       "  'MEAN_INCIDENCE_ZENITH_ANGLE_B7': 4.6223647426,\n",
       "  'DARK_FEATURES_PERCENTAGE': 1.802429,\n",
       "  'HIGH_PROBA_CLOUDS_PERCENTAGE': 0.001271,\n",
       "  'MEAN_INCIDENCE_ZENITH_ANGLE_B6': 4.56114408285,\n",
       "  'UNCLASSIFIED_PERCENTAGE': 31.643507,\n",
       "  'MEAN_SOLAR_ZENITH_ANGLE': 48.0387993303,\n",
       "  'MEAN_INCIDENCE_ZENITH_ANGLE_B8A': 4.68695416699,\n",
       "  'RADIATIVE_TRANSFER_ACCURACY': 0,\n",
       "  'MGRS_TILE': '43QDD',\n",
       "  'CLOUDY_PIXEL_PERCENTAGE': 0.065106,\n",
       "  'PRODUCT_ID': 'S2B_MSIL2A_20181216T053229_N0211_R105_T43QDD_20181216T093845',\n",
       "  'MEAN_INCIDENCE_ZENITH_ANGLE_B10': 4.42091021159,\n",
       "  'SOLAR_IRRADIANCE_B9': 817.58,\n",
       "  'SNOW_ICE_PERCENTAGE': 0,\n",
       "  'DEGRADED_MSI_DATA_PERCENTAGE': 0,\n",
       "  'MEAN_INCIDENCE_ZENITH_ANGLE_B11': 4.54660016841,\n",
       "  'MEAN_INCIDENCE_ZENITH_ANGLE_B12': 4.69679139175,\n",
       "  'SOLAR_IRRADIANCE_B6': 1291.13,\n",
       "  'MEAN_INCIDENCE_AZIMUTH_ANGLE_B10': 103.574736762,\n",
       "  'SOLAR_IRRADIANCE_B5': 1425.78,\n",
       "  'MEAN_INCIDENCE_AZIMUTH_ANGLE_B11': 102.50820176,\n",
       "  'SOLAR_IRRADIANCE_B8': 1041.28,\n",
       "  'MEAN_INCIDENCE_AZIMUTH_ANGLE_B12': 101.797838978,\n",
       "  'SOLAR_IRRADIANCE_B7': 1175.57,\n",
       "  'SOLAR_IRRADIANCE_B2': 1959.77,\n",
       "  'SOLAR_IRRADIANCE_B1': 1874.3,\n",
       "  'SOLAR_IRRADIANCE_B4': 1512.79,\n",
       "  'GEOMETRIC_QUALITY': 'PASSED',\n",
       "  'SOLAR_IRRADIANCE_B3': 1824.93,\n",
       "  'system:asset_size': 1743285975,\n",
       "  'WATER_PERCENTAGE': 0.898059,\n",
       "  'system:index': '20181216T053229_20181216T053648_T43QDD'}}"
      ]
     },
     "execution_count": 46,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "sentinel2_aoi.first().getInfo()"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    " It’s possible to be more selective and filter out the information you don’t want."
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 32,
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/plain": [
       "113"
      ]
     },
     "execution_count": 32,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "sentinel2_aoi.size().getInfo()"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "### Visualizing the Images\n",
    "\n",
    "The Javascript-based code editor easily allows interactive visualization using ```Map.AddLayer()```, but unfortunately, this is not available for the standard Python API. A simple, static map can be made with both the ```.getThumbURL()``` module from ee and the native ```.display()``` module:"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "metadata": {},
   "outputs": [],
   "source": [
    "# Visualizing the first image in the collection\n",
    "rgbVis = {\n",
    "    'min': 0.0,\n",
    "    'max': 3000.0,\n",
    "    'bands': ['B4', 'B3', 'B2'],\n",
    "    'region': geometry}\n",
    "first_img = ee.Image(sentinel2_mh_aoi.first())\n",
    "Image(url= first_img.getThumbUrl(rgbVis))"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 23,
   "metadata": {
    "scrolled": true
   },
   "outputs": [
    {
     "data": {
      "text/html": [
       "<div style=\"width:100%;\"><div style=\"position:relative;width:100%;height:0;padding-bottom:60%;\"><span style=\"color:#565656\">Make this Notebook Trusted to load map: File -> Trust Notebook</span><iframe src=\"about:blank\" style=\"position:absolute;width:100%;height:100%;left:0;top:0;border:none !important;\" data-html=PCFET0NUWVBFIGh0bWw+CjxoZWFkPiAgICAKICAgIDxtZXRhIGh0dHAtZXF1aXY9ImNvbnRlbnQtdHlwZSIgY29udGVudD0idGV4dC9odG1sOyBjaGFyc2V0PVVURi04IiAvPgogICAgCiAgICAgICAgPHNjcmlwdD4KICAgICAgICAgICAgTF9OT19UT1VDSCA9IGZhbHNlOwogICAgICAgICAgICBMX0RJU0FCTEVfM0QgPSBmYWxzZTsKICAgICAgICA8L3NjcmlwdD4KICAgIAogICAgPHNjcmlwdCBzcmM9Imh0dHBzOi8vY2RuLmpzZGVsaXZyLm5ldC9ucG0vbGVhZmxldEAxLjYuMC9kaXN0L2xlYWZsZXQuanMiPjwvc2NyaXB0PgogICAgPHNjcmlwdCBzcmM9Imh0dHBzOi8vY29kZS5qcXVlcnkuY29tL2pxdWVyeS0xLjEyLjQubWluLmpzIj48L3NjcmlwdD4KICAgIDxzY3JpcHQgc3JjPSJodHRwczovL21heGNkbi5ib290c3RyYXBjZG4uY29tL2Jvb3RzdHJhcC8zLjIuMC9qcy9ib290c3RyYXAubWluLmpzIj48L3NjcmlwdD4KICAgIDxzY3JpcHQgc3JjPSJodHRwczovL2NkbmpzLmNsb3VkZmxhcmUuY29tL2FqYXgvbGlicy9MZWFmbGV0LmF3ZXNvbWUtbWFya2Vycy8yLjAuMi9sZWFmbGV0LmF3ZXNvbWUtbWFya2Vycy5qcyI+PC9zY3JpcHQ+CiAgICA8bGluayByZWw9InN0eWxlc2hlZXQiIGhyZWY9Imh0dHBzOi8vY2RuLmpzZGVsaXZyLm5ldC9ucG0vbGVhZmxldEAxLjYuMC9kaXN0L2xlYWZsZXQuY3NzIi8+CiAgICA8bGluayByZWw9InN0eWxlc2hlZXQiIGhyZWY9Imh0dHBzOi8vbWF4Y2RuLmJvb3RzdHJhcGNkbi5jb20vYm9vdHN0cmFwLzMuMi4wL2Nzcy9ib290c3Ry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ICAgICAgICAgICAgPHN0eWxlPgogICAgICAgICAgICAgICAgI21hcF80NDkzMGVlNTgzYTE0NTY1YWI2NGI4MTRlNTdmMDUxNCB7CiAgICAgICAgICAgICAgICAgICAgcG9zaXRpb246IHJlbGF0aXZlOwogICAgICAgICAgICAgICAgICAgIHdpZHRoOiAxMDAuMCU7CiAgICAgICAgICAgICAgICAgICAgaGVpZ2h0OiAxMDAuMCU7CiAgICAgICAgICAgICAgICAgICAgbGVmdDogMC4wJTsKICAgICAgICAgICAgICAgICAgICB0b3A6IDAuMCU7CiAgICAgICAgICAgICAgICB9CiAgICAgICAgICAgIDwvc3R5bGU+CiAgICAgICAgCjwvaGVhZD4KPGJvZHk+ICAgIAogICAgCiAgICAgICAgICAgIDxkaXYgY2xhc3M9ImZvbGl1bS1tYXAiIGlkPSJtYXBfNDQ5MzBlZTU4M2ExNDU2NWFiNjRiODE0ZTU3ZjA1MTQiID48L2Rpdj4KICAgICAgICAKPC9ib2R5Pgo8c2NyaXB0PiAgICAKICAgIAogICAgICAgICAgICB2YXIgbWFwXzQ0OTMwZWU1ODNhMTQ1NjVhYjY0YjgxNGU1N2YwNTE0ID0gTC5tYXAoCiAgICAgICAgICAgICAgICAibWFwXzQ0OTMwZWU1ODNhMTQ1NjVhYjY0YjgxNGU1N2YwNTE0IiwKICAgICAgICAgICAgICAgIHsKICAgICAgICAgICAgICAgICAgICBjZW50ZXI6IFsyMS4wNjUyNjg1MzM3NzUzMSwgNzQuNTEyMTg0MzczNjYwMTNdLAogICAgICAgICAgICAgICAgICAgIGNyczogTC5DUlMuRVBTRzM4NTcsCiAgICAgICAgICAgICAgICAgICAgem9vbTogMTAsCiAgICAgICAgICAgICAgICAgICAgem9vbUNvbnRyb2w6IHRydWUsCiAgICAgICAgICAgICAgICAgICAgcHJlZmVyQ2FudmFzOiBmYWxzZSwKICAgICAgICAgICAgICAgIH0KICAgICAgICAgICAgKTsKCiAgICAgICAgICAgIAoKICAgICAgICAKICAgIAogICAgICAgICA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eH0ve3l9IiwKICAgICAgICAgICAgICAgIHsiYXR0cmlidXRpb24iOiAiR29vZ2xlIEVhcnRoIEVuZ2luZSIsICJkZXRlY3RSZXRpbmEiOiBmYWxzZSwgIm1heE5hdGl2ZVpvb20iOiAxOCwgIm1heFpvb20iOiAxOCwgIm1pblpvb20iOiAwLCAibm9XcmFwIjogZmFsc2UsICJvcGFjaXR5IjogMSwgInN1YmRvbWFpbnMiOiAiYWJjIiwgInRtcyI6IGZhbHNlfQogICAgICAgICAgICApLmFkZFRvKG1hcF80NDkzMGVlNTgzYTE0NTY1YWI2NGI4MTRlNTdmMDUxNCk7CiAgICAgICAgCjwvc2NyaXB0Pg== onload=\"this.contentDocument.open();this.contentDocument.write(atob(this.getAttribute('data-html')));this.contentDocument.close();\" allowfullscreen webkitallowfullscreen mozallowfullscreen></iframe></div></div>"
      ],
      "text/plain": [
       "<folium.folium.Map at 0x16507b197b8>"
      ]
     },
     "execution_count": 23,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "center = geometry.centroid().coordinates()\n",
    "mh_map = folium.Map(location=[center.get(1).getInfo(), center.get(0).getInfo()], zoom_start=10)\n",
    "mh_map.addLayer(first_img, rgbVis)\n",
    "mh_map"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "```geehydro``` allows an even greater degree of reproducibility between the Javascript and Python API. It allows for multiple layer to ve vizualize at the same time. The following code shows both the first image in the collection and the median image as well as the OSM layer and allows you to choose the one you want to display. \n"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 40,
   "metadata": {
    "scrolled": true
   },
   "outputs": [
    {
     "data": {
      "text/html": [
       "<div style=\"width:100%;\"><div style=\"position:relative;width:100%;height:0;padding-bottom:60%;\"><span style=\"color:#565656\">Make this Notebook Trusted to load map: File -> Trust Notebook</span><iframe src=\"about:blank\" style=\"position:absolute;width:100%;height:100%;left:0;top:0;border:none !important;\" data-html=PCFET0NUWVBFIGh0bWw+CjxoZWFkPiAgICAK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yB7CiAgICAgICAgICAgICAgICAgICAgcG9zaXRpb246IHJlbGF0aXZlOwogICAgICAgICAgICAgICAgICAgIHdpZHRoOiAxMDAuMCU7CiAgICAgICAgICAgICAgICAgICAgaGVpZ2h0OiAxMDAuMCU7CiAgICAgICAgICAgICAgICAgICAgbGVmdDogMC4wJTsKICAgICAgICAgICAgICAgICAgICB0b3A6IDAuMCU7CiAgICAgICAgICAgICAgICB9CiAgICAgICAgICAgIDwvc3R5bGU+CiAgICAgICAgCjwvaGVhZD4KPGJvZHk+ICAgIAogICAgCiAgICAgICAgICAgIDxkaXYgY2xhc3M9ImZvbGl1bS1tYXAiIGlkPSJtYXBfMmMzMTc5ODYyNDRmNDViMWI5NmQ3YWQ0ZjczZGQ3ZTciID48L2Rpdj4KICAgICAgICAKPC9ib2R5Pgo8c2NyaXB0PiAgICAKICAgIAogICAgICAgICAgICB2YXIgbWFwXzJjMzE3OTg2MjQ0ZjQ1YjFiOTZkN2FkNGY3M2RkN2U3ID0gTC5tYXAoCiAgICAgICAgICAgICAgICAibWFwXzJjMzE3OTg2MjQ0ZjQ1YjFiOTZkN2FkNGY3M2RkN2U3IiwKICAgICAgICAgICAgICAgIHsKICAgICAgICAgICAgICAgICAgICBjZW50ZXI6IFsyMS4wNjUyNjg1MzM3NzUzMSwgNzQuNTEyMTg0MzczNjYwMTNdLAogICAgICAgICAgICAgICAgICAgIGNyczogTC5DUlMuRVBTRzM4NTcsCiAgICAgICAgICAgICAgICAgICAgem9vbTogMTAsCiAgICAgICAgICAgICAgICAgICAgem9vbUNvbnRyb2w6IHRydWUsCiAgICAgICAgICAgICAgICAgICAgcHJlZmVyQ2FudmFzOiBmYWxzZSwKICAgICAgICAgICAgICAgIH0KICAgICAgICAgICAgKTsKCiAgICAgICAgICAgIAoKICAgICAgICAKICAgIAogICAgICAgICAgICB2YXIgdGlsZV9sYXllcl9kNGVjMDVhMTU5ODA0YzAxYjI5MGI0NWQ2Mzk5MDI0NSA9IEwudGlsZUxheWVy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ICAgICAgICAgICAgICAgICJvcGVuc3RyZWV0bWFwIiA6IHRpbGVfbGF5ZXJfZDRlYzA1YTE1OTgwNGMwMWIyOTBiNDVkNjM5OTAyNDUsCiAgICAgICAgICAgICAgICB9LAogICAgICAgICAgICAgICAgb3ZlcmxheXMgOiAgewogICAgICAgICAgICAgICAgICAgICJtZWRpYW4gY29tcG9zaXRlIiA6IHRpbGVfbGF5ZXJfY2Q3NDM5NzUzNTgwNDBlY2EyNWNmMjVlMjhmZGUzZTMsCiAgICAgICAgICAgICAgICAgICAgIkZpcnN0IEltYWdlIiA6IHRpbGVfbGF5ZXJfNmNlMGU5ZDgyZjQzNDM5MDgyMjkwMjlmYTc1YzBlNmYsCiAgICAgICAgICAgICAgICB9LAogICAgICAgICAgICB9OwogICAgICAgICAgICBMLmNvbnRyb2wubGF5ZXJzKAogICAgICAgICAgICAgICAgbGF5ZXJfY29udHJvbF81MjFhZjYwOWQwMzA0ODY1YTkyNDBmZjRiMTcyMzg4MC5iYXNlX2xheWVycywKICAgICAgICAgICAgICAgIGxheWVyX2NvbnRyb2xfNTIxYWY2MDlkMDMwNDg2NWE5MjQwZmY0YjE3MjM4ODAub3ZlcmxheXMsCiAgICAgICAgICAgICAgICB7ImF1dG9aSW5kZXgiOiB0cnVlLCAiY29sbGFwc2VkIjogdHJ1ZSwgInBvc2l0aW9uIjogInRvcHJpZ2h0In0KICAgICAgICAgICAgKS5hZGRUbyhtYXBfMmMzMTc5ODYyNDRmNDViMWI5NmQ3YWQ0ZjczZGQ3ZTcpOwogICAgICAgIAo8L3NjcmlwdD4= onload=\"this.contentDocument.open();this.contentDocument.write(atob(this.getAttribute('data-html')));this.contentDocument.close();\" allowfullscreen webkitallowfullscreen mozallowfullscreen></iframe></div></div>"
      ],
      "text/plain": [
       "<folium.folium.Map at 0x1650907d550>"
      ]
     },
     "execution_count": 40,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "# Use folium to visualize different data layers.\n",
    "mapid = sentinel2_mh_median_image.getMapId({'bands': ['B4', 'B3', 'B2'], 'min': 0, 'max': 3000})\n",
    "map = folium.Map(location=[center.get(1).getInfo(), center.get(0).getInfo()], zoom_start=10)\n",
    "folium.TileLayer(\n",
    "    tiles=mapid['tile_fetcher'].url_format,\n",
    "    attr='Google Earth Engine',\n",
    "    overlay=True,\n",
    "    name='median composite',\n",
    "  ).add_to(map)\n",
    "mapid = first_img.getMapId({'bands': ['B4', 'B3', 'B2'], 'min': 0, 'max': 3000})\n",
    "folium.TileLayer(\n",
    "    tiles=mapid['tile_fetcher'].url_format,\n",
    "    attr='Google Earth Engine',\n",
    "    overlay=True,\n",
    "    name='First Image',\n",
    "  ).add_to(map)\n",
    "map.add_child(folium.LayerControl())\n",
    "map"
   ]
  }
 ],
 "metadata": {
  "kernelspec": {
   "display_name": "geo_env",
   "language": "python",
   "name": "geo_env"
  },
  "language_info": {
   "codemirror_mode": {
    "name": "ipython",
    "version": 3
   },
   "file_extension": ".py",
   "mimetype": "text/x-python",
   "name": "python",
   "nbconvert_exporter": "python",
   "pygments_lexer": "ipython3",
   "version": "3.6.10"
  }
 },
 "nbformat": 4,
 "nbformat_minor": 4
}
